<template>
	<view class="ranking">
		<view class="bg"></view>
		<view class="ranking-Lists">
			<!-- tabs栏 -->
			<view class="rankingList">
				<view class="rankingList-left">
					<image class="dwImg" src="https://wlsy.nanjingyunpeng.cn/weixin/image/home/radw.png"></image>
					<view class="address">郑州</view>
				</view>
				<view class="rankingList-right">
					<button class="btn" :class="{isbtn:currIndex==0}" @click="weekRanking">周排名</button>
					<button class="btn" :class="{isbtn:currIndex==1}" @click="monthRanking">月排名</button>
					<button class="btn" :class="{isbtn:currIndex==2}" @click="yearRanking">年排名</button>
					<button class="btn" :class="{isbtn:currIndex==3}" @click="historyRanking">历史排名</button>
				</view>
			</view>
			<!-- 奖台 -->
			<view class="podium">
				<image class="podium-img" src="https://wlsy.nanjingyunpeng.cn/weixin/image/home/podiumImg.png"></image>
				<view class="prizeImg-one">
					<image class="touxiangone" :src="dataList[0].imgSrc"></image>
					<image class="prizeFirst" src="https://wlsy.nanjingyunpeng.cn/weixin/image/home/FirstPrize.png">
					</image>
					<image class="prizeOne" src="https://wlsy.nanjingyunpeng.cn/weixin/image/home/one.png"></image>
					<view class="nickname">
						{{dataList[0].nickName ? dataList[0].nickName : ""}}
					</view>
					<view class="score">
						{{dataList[0].score ? dataList[0].score : ""}}分
					</view>
				</view>
				<view class="prizeImg-two">
					<image class="touxiangtwo" :src="dataList[1].imgSrc"></image>
					<image class="prizeSecond" src="https://wlsy.nanjingyunpeng.cn/weixin/image/home/SecondPrize.png">
					</image>
					<image class="prizeTwo" src="https://wlsy.nanjingyunpeng.cn/weixin/image/home/two.png"></image>
					<view class="nickname">
						{{dataList[1].nickName ? dataList[1].nickName : ""}}
					</view>
					<view class="score">
						{{dataList[1].score ? dataList[1].score : ""}}分
					</view>
				</view>
				<view class="prizeImg-three">
					<image class="touxiangthree" :src="dataList[2].imgSrc"></image>
					<image class="prizeThird" src="https://wlsy.nanjingyunpeng.cn/weixin/image/home/ThirdPrize.png">
					</image>
					<image class="prizeThree" src="https://wlsy.nanjingyunpeng.cn/weixin/image/home/three.png"></image>
					<view class="nickname">
						{{dataList[2].nickName ? dataList[2].nickName : ""}}
					</view>
					<view class="score">
						{{dataList[2].score ? dataList[2].score : ""}}分
					</view>
				</view>

			</view>
			<!-- 列表 -->
			<scroll-view class="rankings" scroll-y="true"  v-if="mineitem">
				<view class="rankings-item" v-for="item in xuanranList" :key="id">
					<view class="rankings-item-one">
						<view class="PM">{{item.listNum}}</view>
						<image class="item-img" :src="item.imgSrc"></image>
						<view class="item-nickname">{{item.nickName}}</view>
					</view>
					<view class="item-score">{{item.score}}分</view>
				</view>
			
			</scroll-view>
			<view class="" v-else>
			<u-empty
			        mode="history"
			        icon="http://cdn.uviewui.com/uview/empty/history.png">
			</u-empty>
				
			</view>
			
		</view>
		<view class="mine-item" v-if="mineitem">
			<view class="mine-item-no" v-if="Yvisible">未上榜</view>
			<image class="mine-item-crown" v-else src="https://wlsy.nanjingyunpeng.cn/weixin/image/home/crown.png">
			</image>
			<view class="mine-item-listNum" v-if="!Yvisible">{{mineData.listNum}}</view>
			<image class="mine-item-tx" :src="mineData.avatar"></image>
			<view class="mine-text">我</view>
			<view class="mine-item-score">{{mineData.score}}分</view>
		</view>
	</view>
</template>

<script>
	import {
		ranktop,
		getuserinfo
	} from "../../api/api.js"
	export default {
		data() {
			return {
				currIndex: 0,
				dataList: [],
				xuanranList: [],
				mineData: {
					listNum: 0,
					avatar: "",
					score: 0
				},
				Yvisible: true,
				mineitem:true
			}
		},
		onShow() {
			this.ranktop()
		},
		methods: {
			async ranktop(val) {
				// console.log("val", val)
				let type = val;
				let res = await ranktop({
					type: type
				});
				if (res.code === 1000) {
					// console.log("res", res)
					this.dataList = []
					this.mineData.listNum = res.data.user_rank.rank
					// this.mineData.listNum = 1
					this.mineData.score = res.data.user_rank.num ? res.data.user_rank.num.substring(0, res.data.user_rank.num.length - 3) : ""
					if(res.data.rank.length == 0){
						this.mineitem = false
					}else{
						this.mineitem = true
						res.data.rank.forEach((item, index) => {
							this.dataList.push({
								listNum: index + 1,
								imgSrc: item.avatar,
								nickName: item.nickname,
								score: item.num.substring(0, item.num.length - 3),
								uid: item.uid
							})
						})
						this.xuanranList = this.dataList
						if (this.mineData.listNum ==2) {
							this.Yvisible = true
						}else{
							this.Yvisible = false
						}
					}
					
				}
			},
			//周排名
			weekRanking() {
				this.currIndex = 0
				this.ranktop(1)
			},
			//月排名
			monthRanking() {
				this.currIndex = 1
				this.ranktop(2)
			},
			//年排名
			yearRanking() {
				this.currIndex = 2
				this.ranktop(3)
			},
			//历史排名
			historyRanking() {
				this.currIndex = 3
				this.ranktop(4)
			},
			//获取用户信息
			async getuserinfo() {
				let res = await getuserinfo()
				if (res.code == 1000) {
					// console.log("用户信息", res)
					this.mineData.avatar = res.data.avatar
				}
				// console.log(this.mineData.avatar)
			},

		},
		onLoad() {
			this.getuserinfo()
			this.ranktop(1)
			if (this.mineData.listNum = 1) {
				this.Yvisible = true
				this.Nvisible = false
			} else {
				this.Yvisible = false
				this.Nvisible = true
			}
		}
	}
</script>

<style scoped lang="scss">
	.ranking {
		min-width: 100%;
		min-height: 100%;
		background-color: #EEF7FE;

		.bg {
			width: 100%;
			height: 502rpx;
			background-color: #466EE7;
			border-radius: 0 0 60rpx 60rpx;
		}

		.ranking-Lists {
			position: absolute;
			top: 40rpx;

			.rankingList {
				width: 690rpx;
				// background-color: pink;
				margin-left: 30rpx;

				display: flex;
				align-items: center;

				.rankingList-left {
					display: flex;
					align-items: center;

					.dwImg {
						width: 40rpx;
						height: 40rpx;
					}

					.address {
						font-size: 24rpx;
						font-family: PingFang SC-Regular, PingFang SC;
						font-weight: 400;
						color: #FFFFFF;
						line-height: 32rpx;
					}
				}

				.rankingList-right {
					width: 600rpx;
					display: flex;
					justify-content: space-between;

					.btn {
						width: 135rpx;
						height: 50rpx;
						background-color: #FFFFFF;
						border: 1px solid #FFFFFF;
						border-radius: 12rpx 12rpx 12rpx 12rpx;
						opacity: 1;
						font-size: 24rpx;
						background-color: #466EE7;
						font-family: PingFang SC-Regular, PingFang SC;
						font-weight: 400;
						color: #FFFFFF;
						line-height: 50rpx;
					}

					.isbtn {
						background-color: #FFFFFF;
						color: #466EE7;
					}
				}


			}
		}

		.podium {
			width: 690rpx;
			height: 500rpx;
			// background-color:#FFFFFF;
			margin-left: 30rpx;
			margin-top: 30rpx;


			.podium-img {
				width: 690rpx;
				height: 214rpx;
				position: absolute;
				top: 390rpx;

			}

			.prizeImg-one {

				width: 151rpx;
				height: 216rpx;
				// background-color: pink;
				text-align: center;
				position: absolute;
				top: 183rpx;
				left: 300rpx;

				.touxiangone {
					width: 147rpx;
					height: 147rpx;
					position: absolute;
					border-radius: 106rpx;
					top: 53rpx;
					left: 2rpx;
				}

				.prizeFirst {
					width: 151rpx;
					height: 200rpx;
				}

				.prizeOne {
					width: 178rpx;
					height: 42rpx;
					position: absolute;
					top: 177rpx;
					left: -15rpx;
				}

				.nickname {
					width: 138rpx;
					font-size: 22rpx;
					font-family: PingFang SC-Heavy, PingFang SC;
					font-weight: 800;
					color: #FFFFFF;
					position: absolute;
					text-align: center;
					top: 176rpx;
					left: 0rpx;
					white-space: nowrap;
					overflow: hidden;
					text-overflow: ellipsis;
				}

				.score {
					font-size: 24rpx;
					font-family: PingFang SC-Bold, PingFang SC;
					font-weight: bold;
					color: #775A00;
					line-height: 28rpx;
					margin-top: 20rpx;
				}
			}

			.prizeImg-two {
				width: 108rpx;
				height: 158rpx;
				// background-color: pink;
				text-align: center;
				position: absolute;
				top: 327rpx;
				left: 119rpx;

				.touxiangtwo {
					width: 105rpx;
					height: 105rpx;
					position: absolute;
					border-radius: 106rpx;
					top: 37rpx;
					left: 4rpx;
				}

				.prizeSecond {
					width: 108rpx;
					height: 142rpx;
				}

				.prizeTwo {
					width: 158rpx;
					height: 39rpx;
					position: absolute;
					top: 128rpx;
					left: -25rpx;
				}

				.nickname {
					width: 108rpx;
					font-size: 22rpx;
					font-family: PingFang SC-Heavy, PingFang SC;
					font-weight: 800;
					color: #FFFFFF;
					position: absolute;
					top: 128rpx;
					left: 0rpx;
					white-space: nowrap;
					overflow: hidden;
					text-overflow: ellipsis;
				}

				.score {
					font-size: 24rpx;
					font-family: PingFang SC-Bold, PingFang SC;
					font-weight: bold;
					color: #775A00;
					line-height: 28rpx;
					margin-top: 20rpx;
				}
			}

			.prizeImg-three {
				width: 107rpx;
				height: 158rpx;
				text-align: center;
				position: absolute;
				top: 365rpx;
				right: 75rpx;

				.touxiangthree {
					width: 103rpx;
					height: 103rpx;
					position: absolute;
					border-radius: 106rpx;
					top: 37rpx;
					left: 4rpx;
				}

				.prizeThird {
					width: 107rpx;
					height: 142rpx;
				}

				.prizeThree {
					width: 155rpx;
					height: 40rpx;
					position: absolute;
					top: 120rpx;
					right: -19rpx;
				}

				.nickname {
					width: 100rpx;
					font-size: 22rpx;
					font-family: PingFang SC-Heavy, PingFang SC;
					font-weight: 800;
					color: #FFFFFF;
					position: absolute;
					top: 120rpx;
					left: 0rpx;
					white-space: nowrap;
					overflow: hidden;
					text-overflow: ellipsis;
				}

				.score {
					font-size: 24rpx;
					font-family: PingFang SC-Bold, PingFang SC;
					font-weight: bold;
					color: #775A00;
					line-height: 28rpx;
					margin-top: 20rpx;
				}
			}
		}


		.rankings {
			width: 690rpx;
			height: 680rpx;
			margin-left: 30rpx;
			margin-top: 20rpx;
			background-color: #FFFFFF;

			.rankings-item {
				display: flex;
				align-items: center;
				width: 690rpx;
				justify-content: space-between;
				padding: 0 20rpx;
				box-sizing: border-box;

				.rankings-item-one {
					display: flex;
					align-items: center;
					margin: 20rpx;

					.PM {
						width: 70rpx;
						// background-color: pink;
					}

					.item-nickname {
						width: 250rpx;
						white-space: nowrap;
						overflow: hidden;
						text-overflow: ellipsis;
					}

					.item-img {
						width: 72rpx;
						height: 72rpx;
						margin: 0 30rpx;
					}
				}
			}
		}

		.mine-item {
			width: 100%;
			height: 120rpx;
			background: #FFFFFF;
			box-shadow: inset 0px 1px 0px 0px rgba(0, 0, 0, 0.05);
			border-radius: 0px 0px 0px 0px;
			position: fixed;
			bottom: 0;
			display: flex;
			align-items: center;
			padding: 0 30rpx;

			.mine-item-crown {
				width: 48rpx;
				height: 48rpx;
				margin: 0 20rpx;
			}

			.mine-item-listNum {
				margin-right: 20rpx;
			}

			.mine-item-tx {
				width: 72rpx;
				height: 72rpx;
				border-radius: 50rpx;
				margin: 0 20rpx;
			}

			.mine-text {
				margin-left: 20rpx;
				margin-right: 200rpx;
			}

			.mine-item-score {
				width: 208rpx;
				height: 42rpx;
				text-align: right;
				font-family: PingFang SC-Medium, PingFang SC;
				font-weight: 500;
				color: #333333;
				line-height: 33rpx;
				padding-right: 40rpx;
				box-sizing: border-box;
			}

			.mine-item-no {
				font-size: 28rpx;
				font-family: PingFang SC-Medium, PingFang SC;
				font-weight: 500;
				color: #CA1313;
				line-height: 28rpx;
				margin: 0 20rpx;
			}
		}
	}
</style>
